<link href="admin.css" rel="stylesheet" type="text/css" />
<script src="<{$config.weburl}>/script/jquery-1.4.4.min.js" type="text/javascript" charset="utf-8" ></script>
<{if $smarty.get.operation=='property'}>
    <div class="container">
    	<div class="oflow"  style="height:517px">
        <table class="table4 mt20">
            <thead>
            <tr>
                <td class="pl20">扩展属性值</td>
                <td width="70" class="ac">操作</td>
            </tr>
            </thead>
            <tbody>
            <{foreach item=list from=$re}>
            <tr>
            	<td class="pl20"><input type="text" name="item_name[]" value="<{$list}>" /></td>
            	<td class="ac"><div><a href="javascript:;" class="deleterow" onClick="deleterow(this)">删除</a></div></td>
            </tr>
            <{/foreach}>
            <tr>
                <td colspan="99">
                <ul class="button">
                    <li class="button">
                        <a class="a_button" onClick="addrow(this,0)" href="javascript:void(0);">添加扩展属性值</a>
                    </li>
                </ul>
                </td>
            </tr>
            </tbody>
        </table>
        </div>
        <div class="dialog_button">
        <input id="save" type="button" value="保存">
        <input name="act" type="hidden" id="action" value="<{if !$smarty.get.editid}>save<{else}>edit<{/if}>">   
        </div>
        <div id="error"></div> 
    </div>
    <script>
	$('#save').click(function(){
		var str = '';
		var id = "<{$smarty.get.id}>";
		$.each($(".container input[name='item_name[]']"),function(i){
			
			var aa= $(this).val();
			if(aa)
			{
				if(!str)
					str = aa;
				else
					str = str+','+aa;
			}
		});
	   
        var iframe=window.parent.document.getElementById("iframe_property").contentWindow;

		var ss=iframe.$("#property").find("input[data_type='"+id+"']");
		$.each(ss,function(i){
			$(this).val(str);
		});
        window.parent.DialogManager.close("list");
    });

	var rowtypedata = [
        [
			['<input type="text" name="item_name[]" value="" />','pl20'], 
            ['<div><a href="javascript:;" class="deleterow" onClick="deleterow(this)">删除</a></div>','ac'],
        ],
    ];

	var addrowdirect = 0;
    var j = 1;
	
    function addrow(obj, type) {
        var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
        if(!addrowdirect) {
            var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex);
        } else {
            var row = table.insertRow(obj.parentNode.parentNode.parentNode.parentNode.rowIndex + addrowdirect);
        }
        
        var typedata = rowtypedata[type];
        
        for(var i = 0; i <= typedata.length - 1; i++) {
            
            var cell = row.insertCell(i);
			if(typedata[i][1]) {
				cell.className = typedata[i][1];
			}
            var tmp = typedata[i][0];
            cell.innerHTML = tmp;
        
        }
        addrowdirect = 0;
        j++;
    }
    function deleterow(obj) {
        var table = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
        var tr = obj.parentNode.parentNode.parentNode;
        table.deleteRow(tr.rowIndex);
    }
    </script>
<{else}>
    <{if $de}>
    <script src="<{$config.weburl}>/script/base.js" type="text/javascript" charset="utf-8" ></script>
    <form action="" method="post">
    <div class="container list">
        <div class="left">
            <div class="mt"><h2>请选择规格</h2></div>
            <div class="mc">
            <ul id="ul">
                <{foreach item=list key=num from=$de}>
                    <li>
                        <input type="checkbox" id="id<{$num}>" value="<{$list.id}>" name="id">
                        <label for="id<{$num}>"><{$list.field_name}></label>
                    </li>
                <{/foreach}>
            </ul>
            </div>
        </div>
        <div class="right">
            <div class="mt"><h2>规格预览区</h2></div>
            <div class="mc">
                <div class="tips">请在左侧列表选择规格！</div>
                <{foreach item=list key=num from=$de}>
                <dl class="hidden">
                    <dt>
                    <h2><{$list.field_name}></h2>
                    <p><{$list.field_desc}></p>
                    </dt>
                    <{foreach item=slist from=$list.items}>
                         <dd><{$slist}></dd>
                    <{/foreach}>
                </dl>
                <{/foreach}>
            </div>
        </div>
        <div class="dialog_button">
        <input id="save" type="button" value="保存">
        <input name="act" type="hidden" id="action" value="<{if !$smarty.get.editid}>save<{else}>edit<{/if}>">   
        </div>
        <div id="error"></div> 
    </div>
    </form>  
    <{else}>
        <div class="norecord"><i></i><span>暂无符合条件的数据记录</span></div>
    <{/if}>
    <script>
    $.each($('.left li'),function(i){
        $(this).find("input[type='checkbox']").live('click',function(){
    
            $($('.right dl')[i]).removeClass("hidden").siblings().addClass("hidden");
        });	
    });
    
    $('#save').click(function(){
        var obj=$("input[type='checkbox']:checked");
        if(!obj.length)
        {
            error('error','对不起，请选择数据，再进行操作!');
            return false;
        }
        var iframe=window.parent.document.getElementById("iframe_property").contentWindow;
        
        iframe.addrow("list",'<{$smarty.get.type}>',2);
        window.parent.DialogManager.close("list");
    });
    </script>
<{/if}>